package com.swordget.commons.safe.channel;

import com.swordget.commons.Constant;
import com.swordget.commons.safe.DataChannelService;
import com.swordget.util.EnvUitl;
import org.apache.commons.lang3.StringUtils;;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

/**
 * 代理httpservlet
 * @author  liang.xu
 * @date 2021年5月8日
 */
public class ProxyHttpServletRequestV2 extends HttpServletRequestWrapper {

    private DataChannelService dataChannelContainer=new DataChannelContainer();

    public ProxyHttpServletRequestV2(HttpServletRequest request) {
        super(request);
    }


    /**
     * 根据参数名获取数值
     * @param name
     * @return
     */
    @Override
    public String getParameter(String name) {
        String targetValue=this.getRequest().getParameter(name);
        if(StringUtils.isBlank(targetValue)){
            return targetValue;
        }
        String url=getRequestURI();
        if(url.contains("editPasswordSys_User")){
            return targetValue;
        }
        return dataChannelContainer.channel(targetValue);
    }


    @Override
    public String getServerName() {
        String rcDomainName= EnvUitl.props.getProperty(Constant.rc_domain_name);
        if(StringUtils.isNotBlank(rcDomainName)){
            return rcDomainName;
        }
        return super.getServerName();
    }
}